package main


import (
    "io"
    "log"
    "net"
    "os"
)

func main() {
    conn, err := net.Dial("tcp", "localhost:8000")
    if err != nil {
        log.Fatal(err)
    }
	done := make(chan struct{})

	go func() {
		// 折扣
		io.Copy(os.Stdout, conn)
		log.Println("done")
		done <- struct{}{}
	}()

    mustCopy(conn, os.Stdin)
	conn.Close()

	// 挂起 等待结束信号
	<- done
}

func mustCopy(dst io.Writer, src io.Reader) {
    if _, err := io.Copy(dst, src); err != nil {
        log.Fatal(err)
    }
}